mui.plusReady(function() {
	var self = plus.webview.currentWebview();
	var url_sign = self.url_sign;
	// 判断是否需要返回键
	if(url_sign == "home") {
		$(".mui-action-back").removeClass("disno");
	} else {
		muiBack();
	}

	if (localStorage.getItem('storeName')) {
		console.log(localStorage.getItem('storeName'))
		$('.headTitle').html(localStorage.getItem('storeName'));
	}

	//订单数据		
	var page = 1;
	var num = 8;
	var timeType = 1;
	mui.init({
		pullRefresh: {
			container: '#xj-list',
			down: {
				contentrefresh: "正在刷新...", //可选，正在刷新状态时，下拉刷新控件上显示的标题内容
				callback: pulldownRefresh
			},
			up: {
				auto: true,
				contentrefresh: '正在加载...',
				callback: pullupRefresh
			}
		}
	});

	/**
	 * 下拉刷新具体业务实现
	 */
	function pulldownRefresh() {
		var str = ""
		page = 1;
		console.log(timeType);
		console.log(page);
		console.log(num);
		require(weburl + model1, "json", "post", {
			token: localStorage.getItem("token"),
			number: num,
			page: page++,
			time_type: timeType
		}, function(res) {
			for(var key = 0; key < res.data.length; key++) {
				str += '<li class="mui-table-view-cell mui-media list_d" data-payId="' + res.data[key].id + '" data-id="' + res.data[key].out_trade_no + '" data-trade="' + res.data[key].trade_no + '">';
				str += '<a class="list_detail">';
				str += '<img class="mui-media-object mui-pull-left" src="' + imageN(res.data[key].pay_type) + '">';
				str += '<div class="mui-media-body">' + res.data[key].created_at.date + '<p class="trade_no">订单号：' + res.data[key].out_trade_no + '</p>';
				str += '<p class="mui-ellipsis" style="color:coral">' + res.data[key].pay_status_txt + '</p>';
				str += '<span class="amout">' + res.data[key].total_amount + '</span></div></a></li>';
			}
			$("#pullrefresh").html(str);
			mui("#xj-list").pullRefresh().endPulldownToRefresh(false);
			mui("#xj-list").pullRefresh().enablePullupToRefresh();
			mui("#xj-list").pullRefresh().endPullupToRefresh(false);
			$(".lanzi").eq(0).html(res.count.amount);
			$(".countAll").html(res.count.bisu);
			$("#no_data").addClass("disno");
			mui('#xj-list').pullRefresh().endPulldownToRefresh();
		}, function() {
			mui.toast("网络错误", {
				duration: "long",
				type: "div"
			})
		})

	}

	/**
	 * 上拉加载具体业务实现
	 */
	function pullupRefresh() {
		console.log(page);
		console.log(num);
		require(weburl + model1, "json", "post", {
			token: localStorage.getItem("token"),
			number: num,
			page: page,
			time_type: timeType
		}, function(res) {
			var str = "";
			console.log(JSON.stringify(res));
			console.log(res.data.length);
			for(var key = 0; key < res.data.length; key++) {
				str += '<li class="mui-table-view-cell mui-media list_d" data-payId="' + res.data[key].id + '" data-id="' + res.data[key].out_trade_no + '" data-trade="' + res.data[key].trade_no + '">';
				str += '<a class="list_detail">';
				str += '<img class="mui-media-object mui-pull-left" src="' + imageN(res.data[key].pay_type) + '">';
				str += '<div class="mui-media-body">' + res.data[key].created_at.date + '<p class="trade_no">订单号：' + res.data[key].out_trade_no + '</p>';
				str += '<p class="mui-ellipsis" style="color:coral">' + res.data[key].pay_status_txt + '</p>';
				str += '<span class="amout">' + res.data[key].total_amount + '</span></div></a></li>';
			}
			$("#pullrefresh").append(str);
			$(".lanzi").eq(0).html(res.count.amount);
			$(".countAll").html(res.count.bisu);
			if(res.data.length < num) {
				$("#no_data").removeClass("disno");
				mui('#xj-list').pullRefresh().endPullupToRefresh(true);
//				mui("#xj-list").pullRefresh().disablePullupToRefresh();
				return false;
			}
			page++;
//			mui("#xj-list").pullRefresh().endPullupToRefresh(false);
			mui('#xj-list').pullRefresh().endPullupToRefresh(false);
			mui('#xj-list').pullRefresh().refresh(true);
		}, function() {
			mui.toast("网络错误", {
				duration: "long",
				type: "div"
			})
		})
	}

	//点击对应订单跳转到详情页面
	mui('body').on('tap', '.list_d', function() {
		//			localStorage.setItem('orderNum', $(this).attr("data-id"));
		//			localStorage.setItem("payId", $(this).attr("data-payId"));
		console.log($(this).attr("data-trade"))
		mui.openWindow({
			url: "detail.html",
			id: "detail",
			extras: {
				orderNum: $(this).attr("data-id"),
				authNo: $(this).attr("data-trade")
			}
		})
	})

	//点击"查询"按钮跳转至日期查询页面
	mui("body").on("tap", ".search", function() {
		mui.openWindow("my/zhangben/se1.html", "se1");
	})

	var urls = ["my/zhangben/se.html", "my/zhangben/se1.html", "my/zhangben/se2.html"];
	mui('body').on("tap", ".classify", function() {
		mui.openWindow({
			url: urls[$(this).index()],
			id: urls[$(this).index()],
			styles: {
				top: 0, //新页面顶部位置
				bottom: 0, //新页面底部位置
			},
			createNew: false, //是否重复创建同样id的webview，默认为false:不重复创建，直接显示
		})
	})

	function imageN(payType) { //图片函数
		var sta = "";
		if(payType == "支付宝") {
			sta = "../img/zhifubao.png";
		} else if(payType == "微信") {
			sta = "../img/weixin.png";
		} else if(payType == "银行卡") {
			sta = "../img/SfBank.png";
		} else {
			sta = "../img/dp.png";
		}
		return sta;
	}
    // 支付状态
	function payStatus(numb) {
		var sta = "";
		switch(numb) {
			case 1:
				sta = "支付成功";
				break;
			case 2:
				sta = "支付取消";
				break;
			case 3:
				sta = "等待支付";
				break;
			case 4:
				sta = "已退款";
				break;
			case 5:
				sta = "订单关闭";
				break;
		}
		return sta;
	}
})